package club.beimeng.emailserver2.utils;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CheckEmailNumber {

    public static boolean check(String email){
        //检测邮件地址是否合法
        String check = "^[A-Za-z0-9\\u4e00-\\u9fa5]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
        Pattern regex = Pattern.compile(check);
        Matcher matcher = regex.matcher(email);
        return matcher.matches();
    }

    /**
     *
     * @param emails
     * @return -1 代表正常，否则代表不支持的位置
     */
    public static Map<Integer,String> checkThemIllegal(String emails){
        String[] split = emails.split(",");
        HashMap<Integer, String> illegal = null ;
        for (int i = 0; i < split.length; i++) {
            if (!check(split[i])){
                if(illegal == null)
                    illegal = new HashMap<>();
                illegal.put(i,split[i]);
            }
        }
        return illegal;
    }


    @Test
    public void test(){
        System.out.println(check("baolong@beimeng.club"));

        String them = "bao_long@beimeng.club,小艾@be.cl.ub,we@@qq.c.om,s s@yes.club";
        System.out.println(checkThemIllegal(them));
    }
}
